// ignore_for_file: overridden_fields

/*
 * @Author: CodeHare
 * @Date: 2023-11-21 14:54:20
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-05-11 16:55:41
 * @Description: 我的报障单单据详情
 */
import 'package:get/get.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:yt_devops/configs.dart';
import 'package:yt_devops/model/info_item.dart';
import 'package:yt_devops/model/task_detail_model.dart';
import 'package:yt_devops/model/task_tail_model.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/utils/enums.dart';
import 'package:yt_devops/utils/func_utils.dart';

class FaultReportDetailModel extends TaskDetailModel<ReportTaskStatusType> {
  @override
  ReportTaskStatusType? status;
  String? siteName;

  /// 0-创建客户报障单  1-处理完成报障单
  int? eventId;

  FaultReportDetailModel({
    super.id,
    super.name,
    super.address,
    super.content,
    super.handlerBy,
    super.orgId,
    super.phone,
    super.timeOfAppointment,
    super.userId,
    super.userName,
    super.createName,
    super.handlerName,
    super.orgName,
    super.descPicUrl,
    super.processingResults,
    super.site,
    super.tails,
    this.status,
    this.siteName,
    this.eventId,
  });

  factory FaultReportDetailModel.fromJson(Map<String, dynamic> json) =>
      FaultReportDetailModel(
        id: json['id'],
        name: json['name'],
        siteName: json['siteName'],
        address: json['address'],
        content: json['content'], // 问题描述
        handlerBy: json['handlerBy'],
        orgId: json['orgId'],
        phone: json['phone'],
        timeOfAppointment: json['timeOfAppointment'],
        userId: json['userId'],
        orgName: json['orgName'],
        handlerName: json['handlerName'],
        userName: json['userName'],
        createName: json['createName'],
        descPicUrl: json['descPicUrl'],
        processingResults: json['processingResults'],
        eventId: json['eventId'],
        tails: List.of(
          json['tails'],
        ).map((e) => TaskTailModel.fromJson(e)).toList(), // 进度
        status:
            $enumDecodeNullable($ReportTaskStatusTypeEnumMap, json['status']),
      );

  /// 基础信息
  List<InfoItem> get baseInfos {
    return [
      InfoItem("${ResKey.siteName.tr}:", siteName ?? ''),
      InfoItem("${ResKey.failureTitle.tr}:", name ?? ''),
    ];
  }

  /// 问题描述
  String get problemDescription {
    return content ?? '';
  }

  /// 进度信息
  List<TaskTailModel> get tasilInfos {
    List<TaskTailModel> taillList;

    if (status == ReportTaskStatusType.finish) {
      taillList = [
        TaskTailModel(name: ResKey.reporter.tr),
        TaskTailModel(name: ResKey.handleFinish.tr),
      ];
    } else {
      taillList = [
        TaskTailModel(name: ResKey.reporter.tr),
        TaskTailModel(name: ResKey.repairing.tr),
        TaskTailModel(name: ResKey.repaired.tr),
      ];
    }

    if (tails != null) {
      for (var i = 0; i < tails!.length; i++) {
        tails![i].name = taillList[i].name;
        taillList[i] = tails![i];
      }
    }

    return taillList;
  }

  /// 故障图片
  List<String>? get pics {
    List<String> picList = [];

    if (FuncUtils.isEmpty(descPicUrl)) return [];

    var picOriginUrl = descPicUrl!.split(',');
    if (picOriginUrl.isEmpty) return null;

    for (var e in picOriginUrl) {
      picList.add(e);
    }
    return picList;
  }

  /// 展示处理人
  bool get isShowReceiver {
    if (status != ReportTaskStatusType.waitingForProcessing) {
      return true;
    } else {
      return false;
    }
  }

  /// 展示手机号
  bool get isShowPhone {
    if (status != ReportTaskStatusType.waitingForProcessing) {
      return true;
    } else {
      return false;
    }
  }

  /// 展示处理意见
  bool get isShowSuggestion {
    if (status == ReportTaskStatusType.finish) {
      return true;
    } else {
      return false;
    }
  }
}
